package com.ja.openchat.ui.chat.multimsg;

import android.content.Context;

import androidx.lifecycle.ViewModelProvider;

import com.ja.openchat.R;
import com.zy.openchat.core.model.message.UiMessage;
import com.zy.openchat.core.model.user.UserInfo;
import com.ja.openchat.ui.chat.MessageViewModel;

import java.util.List;

public class RevokeMessageAction extends MultiMessageAction {

    @Override
    public void onClick(List<UiMessage> messages) {
        MessageViewModel messageViewModel = new ViewModelProvider(fragment).get(MessageViewModel.class);
        for (UiMessage message : messages) {
            messageViewModel.recallMessage(message.message);
        }
    }

    @Override
    public int iconResId() {
        return R.drawable.menu_chexiao_selector;
    }

    @Override
    public String title(Context context) {
        return context.getString(R.string.revoke_text);
    }

    @Override
    public boolean confirm() {
        return true;
    }

    @Override
    public String confirmPrompt(Context context) {
        return context.getString(R.string.confirm_revoke);
    }

    @Override
    public boolean checkActionEnable(List<UiMessage> checkedMessages) {
        boolean isNotEmpty = super.checkActionEnable(checkedMessages);
        if(isNotEmpty){
            if(conversation.isGroup()){
                for(UiMessage message:checkedMessages){
                    if(message.message.sender_user_id() != UserInfo.getUserInfo().id){
                        return false;
                    }
                }
                return true;
            }else{
                return true;
            }
        }else{
            return false;
        }
    }
}
